package com.jwgf.smarowindingmachine_unity.ui;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.Log;

import com.jwgf.common.AppContext;
import com.jwgf.smarowindingmachine_unity.R;

import java.util.Arrays;

public class WaitProgressDialog {
    private static ProgressDialog dlg;
    private static Runnable runnable = new Runnable() {
        @Override
        public void run() {
            if (SmaroWindingMachineActivity.canHandStack != null) {
                SmaroWindingMachineActivity.canHandStack.clearAllCmdList();
//                Log.e("HandShakeTimeout", "清除队列");

            }
            hide();
        }
    };

    public static void show(Context context) {
        if (dlg == null) {
            dlg = ProgressDialog.show(context, AppContext.getInstance().getString(R.string.wait), AppContext.getInstance().getString(R.string.download));
            new Handler(Looper.getMainLooper()).postDelayed(runnable, 5 * 60 * 1000);
        }
        dlg.show();
    }

    public static void hide() {
        if (dlg != null) {
            dlg.dismiss();
            new Handler(Looper.getMainLooper()).removeCallbacks(runnable);
        }
    }
}
